#include "napi/native_api.h"
#include "napi_har.h"



double harNativeAdd(double a, double b) {
    return a + b;
}
// [End harNativeAdd_start]

// [Start set_start]
// staticModule\src\main\cpp\napi_har.cpp
void setHarEnv(napi_env env) {
    g_main_env = env;
}
// [End set_start]

// [Start har_add_start]
// staticModule\src\main\cpp\napi_har.cpp
napi_value harArkTSAdd(double a, double b) {
    napi_env env = g_main_env;
    napi_value module;

    napi_status status = napi_load_module_with_info(env, "entry/src/main/ets/utils/Util", "com.example.crossmodule/entry", &module);
//    if(napi_invalid_arg==status)
//        {
//        napi_value result;
//        napi_create_double(env,8, &result);
//        return result;
//        }
    if (napi_ok != status) {
        return 0;
    }
     napi_value addFunc;
    napi_get_named_property(env, module, "add", &addFunc);

    napi_value addResult;
    napi_value argv[2] = {nullptr, nullptr};
    napi_create_double(env, a, &argv[0]);
    napi_create_double(env, b, &argv[1]);
    napi_call_function(env, module, addFunc, 2, argv, &addResult);

    return addResult;
}